home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group99a.txt / 000157_icon-group-sender _Sun Jul 18 15:23:12 1999.msg < prev    next >
Internet Message Format  |  2000-09-20  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id PAA07496
  4.     for icon-group-addresses; Sun, 18 Jul 1999 15:22:58 -0700 (MST)
  5. Message-Id: <199907182222.PAA07496@baskerville.CS.Arizona.EDU>
  6. To: icon-group@optima.CS.Arizona.EDU
  7. Date: Thu, 15 Jul 1999 21:08:44 -0500
  8. From: memphis@macconnect.com (Garry)
  9. Subject: [Q][newbie] Why use a useless loop?
  10. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  11. Status: RO
  12.  
  13. There is a wonderful little procedure, lastname(s), in the Icon Library
  14. for extracting the last name from a string s representing a person's
  15. full name. (It seems wonderful to me considering how compact yet
  16. tolerant it is, and how I would write it in other languages <ugh>). 
  17.  
  18. e.g. lastname("Dr. I. M. Zany, Jr.") produces a "Zany" result.
  19.  
  20. The implementation is
  21. #       File:     lastname.icn
  22. #       Subject:  Procedure to produce last name
  23. #       Author:   Ralph E. Griswold
  24. #       Date:     April 30, 1993
  25. #
  26. #  Produces the last name of a name in conventional form.  Obviously, it
  27. #  doesn't work for every possibility.
  28.  
  29. procedure lastname(s)
  30.    local line, i
  31.  
  32.    while line := trim(s) do {
  33.       line ?:= tab(upto(',')) # Get rid of things like " ... , Jr."
  34.       line ? {
  35.           every i := upto(' ')
  36.           tab(\i + 1)
  37.           return tab(0)
  38.           }
  39.       }
  40. end
  41.  
  42.  
  43. My problem is that I can't think of any reason for writing
  44.   while line := trim(s) do { ... }
  45. instead of just
  46.    line := trim(s)
  47.  
  48. Can anyone see a need for the "while"?  If so, please teach me. I did of
  49. course already spend more than one full minute thinking about this and
  50. looked up trim() in the Icon book. Maybe there really is no need for the
  51. "while" but then I've observed that I'm blind to my blind spots.
  52.  
  53. -- 
  54. Garry
  55. Tech Writer & Freelance Programmer
  56.